import axios from "axios";
import { useUserStore } from "@/stores/user";

export const http = axios.create({
  baseURL: "/api",
  timeout: 2000000,
});
// 请求拦截器
http.interceptors.request.use(
  (config) => {
    const userStore = useUserStore();
    if (userStore.token !== "") {
      config.headers["Authorization"] = userStore.token;
    }
    return config;
  },
  (error) => {    
    return Promise.reject(error);
  }
);
// 响应拦截器
http.interceptors.response.use(
  (response) => {
    return response.data;
  },
  (error) => {
    console.log(error);
    
    return Promise.reject(error);
  }
);
